import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    children:[
      {
        path:"/users",
        name:"users",
        component:()=>import('../views/users.vue')
      },
      {
        path:"/reports",
        name:"reports",
        component:()=>import('../views/reports.vue')
      },
      {
        path:"/roles",
        name:"roles",
        component:()=>import('../views/roles.vue')
      },
      {
        path:"/params",
        name:"params",
        component:()=>import('../views/params.vue')
      },
      {
        path:"/rights",
        name:"rights",
        component:()=>import('../views/rights.vue')
      },
      {
        path:"/add",
        name:"add",
        component:()=>import('../views/add.vue')
      },
      {
        path:"/goods",
        name:"goods",
        component:()=>import('../views/goods.vue')
      },
      {
        path:"/orders",
        name:"orders",
        component:()=>import('../views/orders.vue')
      },
      {
        path:"/categories",
        name:"categories",
        component:()=>import('../views/categories.vue')
      },
    
   
    ]
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },

  {
    path: '/',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/login.vue')
  },
  
 
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


//白名单—意思是不需要token.就可直接进入页面
const whiteList=['/login','/test']

//路由守卫

// router.beforeEach((to,from,next)=>{
//   //有token或没token
//   let token=localStorage.getItem("token")

//   if(token){
//     next()
//   }
//     else{
//       //注意这里没token又分2种情况 1.在登录页/或者其他不需要token页面就跳转
//       //2.去相应页面
//       if(whiteList.indexOf(to.path)!=-1){
//         next()
//       }
//       else{
//         next('/login')
//       }
//     }
  

// })




export default router
